const db = wx.cloud.database()

Page({
  data: {
    swiperImgUrls: [],//轮播图图片
    goodslist: [],
  },
  onLoad: function (options) {
    this._getSwiper()
    this._getGoodslist()
  },
  _getSwiper() {
    db.collection('swiper').get().then((res) => {
      this.setData({
        swiperImgUrls: res.data
      })
    })
  },
  _getGoodslist() {
    db.collection('goods').get().then((res) => {
      this.setData({
        goodslist: res.data
      })
    })
  },
  onPullDownRefresh: function () {
    this._getGoodslist()
    this._getSwiper()
  },

  onDetail: function (e) {
    var index = e.currentTarget.dataset.id;
    console.log(index);
    wx.setStorageSync("goods", this.data.goodslist[index]);
    wx.navigateTo({
      url: '../goodsdetail/goodsdetail',
    });
  }
})
